package com.dkd.day20250619;

import com.dkd.day20250616.TreeNode;

public class SolutionisValidBST {
    public static void main(String[] args) {

    }

    int pre = Integer.MIN_VALUE;
    public boolean isValidBST (TreeNode root) {
        // write code here
        //使用中序遍历，不断比较
        if(root == null) return true;
        //先进入左子树
        if(!isValidBST(root.left)) return false;
        if(pre > root.val) return false;
        //更新值
        pre = root.val;
        //遍历右子树

        return isValidBST(root.right);
    }
}
